<?php 
	require_once "../Security/validateSession.php";
	require_once "../classes/DB.php";
	require_once "../lib/menu.php";
	require_once "../lib/utils.php";
	checkSession();
?>
<html><!-- InstanceBegin template="/Templates/tmpl.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Operadora IRENK</title>
<!-- InstanceEndEditable -->

<script language="javascript" src="../js/utils.js"></script>
<link href="../css/base.css" rel="stylesheet" type="text/css" />
<link href="../css/irenk.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" -->
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css">
<!-- InstanceEndEditable -->
</head>

<body topmargin="0">
<table border="0" cellpadding="0" cellspacing="0" align="center" style="height:100%;">
    <tr>
    <td height="100%" width="25" class="leftMargin" ></td>
    <td><table width="900" border="0" align="center" cellpadding="0" cellspacing="0" height="100%">
        <tr>
          <td class="headerPixel" width="500" height="70" valign="top">
          	&nbsp;&nbsp;&nbsp;
            <img src="../images/temp/logo.jpg"></td>
            <td class="header" width="205" height="70"></td>
        </tr>
        <tr>
            <td class="back" colspan="2">
       	  	<table border="0" cellpadding="0" cellspacing="0" width="900" height="100%">
                	<tr>
                    	<td width="170" valign="top">
                        	<?php 
							echo '<br />&nbsp;&nbsp;&nbsp;Bienvenido(a)<br>&nbsp;&nbsp;&nbsp;'.$_SESSION["Nombre"].'<br />';
							createMenu(); 
							
							?>
                        </td>
                        <td rowspan="2" width="712" align="center" valign="top">
                        	<br />
                            <!-- InstanceBeginEditable name="submenu" -->
                            <?php 								
								require_once "../classes/DepositosReferenciados.php";
								require_once "../classes/Reservacion.php";
								require_once "../classes/CuentaOperadora.php";
								$profile=get_object_vars(unserialize($_SESSION['userProfile']));
								$idAgencia=$profile['data']['id_procedencia'];
								
							?>
                            <style type="text/css">
								@import url("../css./reports.css");
							</style>
                            <!-- InstanceEndEditable -->
                       	  <!-- InstanceBeginEditable name="body" -->                            	
               		  			<table class="mainTable"  cellpadding="0" cellspacing="0" width="95%" height="90%">
                                	<tr><th>Depositos Referenciados</th></tr>
                                    <tr><td valign="top">
                                    
                                    <br>
                                    <?php
									
										
										if(isset($_GET["accion"])){
										
										if($_GET["accion"] == "save"){
											$toSave = new DepositosReferenciados(array());
											$toSave->Id_Reservacion = $_POST["cb_res"];
											$toSave->Status = $_POST["cb_status"];
											$toSave->Monto = $_POST["txt_monto"];
											$toSave->Tipo_Pago = $_POST["cb_tipo_pago"];
											$toSave->Id_Cuenta_Oper = $_POST["cb_cuenta"];
											$toSave->Id_Agencia = $idAgencia;
											DepositosReferenciados::save($toSave);
										}else if($_GET["accion"] == "delete"){
											$toSave = new DepositosReferenciados(array());
											$toSave->Id_Reservacion = $_GET["id_res"];
											$toSave->Id_Agencia = $idAgencia;
											DepositosReferenciados::delete($toSave);
										}else{
										
										$reservaciones = Reservacion::getReservacionesByAgencia($idAgencia);
										$cuentas = CuentaOperadora::getAllCuentas();
										if($_GET["accion"] == "edit"){
											$selDepos = DepositosReferenciados::getDepositoReferenciadoById_Reservacion($_GET["id"]);
										}else{
											$selDepos = new DepositosReferenciados(array());
										}
										
									?>
                                    <form name="form1" method="post" action="depositosReferenciados.php?accion=save">
                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <caption class="formtitle">
                                        Editar Deposito Referenciado
                                      </caption>
                                      <tr>
                                        <td align="right" class="formLabel">Reservaci&oacute;n:</td>
                                        <td>
                                          <select name="cb_res" id="cb_res">
                                          	
                                          	<?php
												foreach($reservaciones as &$reservacion){
													$sel = "";
													if($reservacion->Id_Reservacion == $selDepos->Id_Reservacion){	
														$sel = "selected";														
													}
											 		echo "<option ".$sel." label='".$reservacion->Id_Reservacion."-".$reservacion->Titulo_Cliente." ".$reservacion->Nombre_Cliente."' value='".$reservacion->Id_Reservacion."'/>";
											 
											 	} ?>
                                          </select>                                       </td>
                                      </tr>
                                      <tr>
                                        <td align="right" class="formLabel">Estado:</td>
                                        <td>
                                          <select name="cb_status" id="cb_status">
                                          	<option label="Referenciado" value="Referenciado" <?php if($selDepos->Status == "Referenciado") echo "selected"; ?>/>
                                            <option label="No Referenciado" value="No Referenciado" <?php if($selDepos->Status == "NoRefrenciado") echo "selected"; ?>/>
                                          </select>                                     </td>
                                      </tr>
                                      <tr>
                                        <td align="right" class="formLabel">Tipo de Pago:</td>
                                        <td>
                                          <select name="cb_tipo_pago" id="cb_tipo_pago" >
                                          	<option label="Efectivo" value="Efectivo" <?php if($selDepos->Tipo_Pago == "Efectivo") echo "selected"; ?>/>
                                            <option label="Tarjeta" value="Tarjeta" <?php if($selDepos->Tipo_Pago == "Tarjeta") echo "selected"; ?>/>
                                            <option label="Cheque" value="Cheque" <?php if($selDepos->Tipo_Pago == "Cheque") echo "selected"; ?>/>
                                            <option label="Deposito" value="Deposito" <?php if($selDepos->Tipo_Pago == "Deposito"){ echo "selected"; }?>/>
                                            <option label="Transferencia" value="Transferencia" <?php if($selDepos->Tipo_Pago == "Transferencia") echo "selected"; ?>/>
                                            <option label="Otro" value="Otro" <?php if($selDepos->Status == "Otro") echo "selected"; ?>/>
                                          </select>                                                                                </td>
                                      </tr>
                                      <tr>
                                        <td align="right" class="formLabel">Monto:</td>
                                        <td>
                                        <span id="sprytextfield1">
                                        <input type="text" name="txt_monto" id="txt_monto" value="<?php echo $selDepos->Monto; ?>">
                                          <span class="textfieldInvalidFormatMsg">Formato invalido.</span></span>                                        </td>
                                      </tr>
                                      <tr>
                                        <td align="right" class="formLabel">N&uacute;mero de cuenta:</td>
                                        <td>
                                          <select name="cb_cuenta" id="cb_cuenta">
                                          	<?php
												foreach($cuentas as &$cuenta){
											 		echo "<option label='".$cuenta->Banco."-".$cuenta->Numero_Cuenta."' value='".$cuenta->Id_Cuenta_Oper."'/>";
											 
											 	} ?>
                                          </select>                                       </td>
                                      </tr>
                                      <tr>
                                        <td colspan="2" align="center"><input type="button" value="Cancelar" onclick="window.location='depositosReferenciados.php'"/>&nbsp;<input type="submit" value="Guardar"/></td>
                                      </tr>
                                    </table>	
                                    </form>
                                    
                                    
									<?php	
										} }
									
									?>
                                    
                                    <table class="report" border="1" width="100%">
                                    	<tr>
                                       	  <th class='formLabel' scope='col'>Reservaci&oacute;n
                                          </th>
                                            <th class='formLabel' scope='col'>Estado
                                          </th>
                                            <th class='formLabel' scope='col'>Tipo de Pago
                                          </th>
                                            <th class='formLabel' scope='col'>Monto
                                          </th>
                                            <th class='formLabel' scope='col'>N&uacute;mero De Cuenta
                                          </th>
                                            <th class='formLabel' scope='col' >Editar
                                            </th>
                                            <th class='formLabel' scope='col' >Eliminar
                                            </th>
                                      </tr>
                                         <?php
										 	$depositos = DepositosReferenciados::getDepositosReferenciadosByAgenciaId($idAgencia);
											foreach($depositos as &$deposito){
										?>
                                        	<tr>
                                            	<td>
                                                	<?php echo $deposito->Id_Reservacion; ?>
                                                </td>
                                                <td>
                                                	<?php echo $deposito->Status; ?>
                                                </td>
                                                <td>
                                                	<?php echo $deposito->Tipo_Pago; ?>
                                                </td>
                                                <td>
                                                	<?php echo $deposito->Monto; ?>
                                                </td>
                                              <td>
                                                	<?php echo $deposito->Cuenta_Operadora->Numero_Cuenta; ?>
                                              </td>
                                                <td><img border='0' style="vertical-align:middle;" src='../images/edit.jpg' value='Modificar' alt='Modificar' onMouseOver="this.style.border='1px outset #000000';" onMouseOut="this.style.border='0px outset #CCCCCC';" onClick="window.location = 'depositosReferenciados.php?accion=edit&id=<?php echo $deposito->Id_Reservacion; ?>'">
                                                </td>
                                                <td><img border='0' src='../images/erase.jpg' alt='Eliminar' onMouseOver="this.style.border='1px outset #000000';" onMouseOut="this.style.border='0px outset #CCCCCC';" onClick="window.location ='depositosReferenciados.php?accion=delete&id_res=<?php echo $deposito->Id_Reservacion; ?>'"></td>
                                            </tr>
                                        <?php
										
											}
										?>
                                      </table>
                                    	<br>
                                        <input type="button" onClick="window.location='depositosReferenciados.php?accion=add'"  value="Agregar"/>
                                    
                                    </td></tr>
                                </table>                            
                                <script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "currency", {validateOn:["change"], isRequired:false});
//-->
                                </script>
                        	<!-- InstanceEndEditable -->
                            <br />
                        </td>
                  </tr>
                  <tr>
                  	<td class="menuImage" width="170">&nbsp;</td>                  
                  </tr>
                </table>
            </td>
        </tr>
        <tr>
          <td colspan="2" class="footer" height="24"></td>
        </tr>
    </table></td>
  	<td width="25" class="rightMargin"></td>
	</tr>
</table>
</body>
<!-- InstanceEnd --></html>
